<template>
  <div class="login_body">
    <div class="login">
      <div class="container a-container">
        <el-form :model="user" class="form" :rules="rules">

          <el-form-item>
            <h2 class="title">重 置 密 码</h2>
          </el-form-item>

          <el-form-item prop="newPwd">
            <el-input type="password" v-model="user.password" clearable="true" class="form_input" placeholder="请输入新密码" show-password></el-input>
          </el-form-item>
          <el-form-item prop="reNewPwd">
            <el-input type="password" v-model="user.rePassword" clearable="true" class="form_input" placeholder="请再次确认密码" show-password></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" size="medium" @click="resetpwd()" round>重置密码</el-button>
          </el-form-item>
        </el-form>
      </div>

      <div class="switch">
        <div class="switch_circle"></div>
        <div class="switch_circle switch_circle-t"></div>

        <div class="switch_container" id="switch-c1">
          <h2 class="title" style="font-size: 30px;">密 码 重 置 中</h2>
          <p class="description"></p>
        </div>
      </div>
    </div>
  </div>
</template>

<style>
@import "@/assets/loginandregister.css";
</style>

<script>

import request from "@/utils/request";

export default {
  name: "ResetPwd",
  data() {
    return {
      user: {
        account: localStorage.getItem("account"),
        password:'',
        rePassword: ''
      },
    }
  },
  // 页面加载的时候，做一些事情，在created里面
  created() {

  },
  // 定义一些页面上控件出发的事件调用的方法
  methods: {
    resetpwd() {
      if (this.user.password === this.user.rePassword){
        request.post("/user/resetpwd",this.user).then(res  => {
          if (res.code === '0'){
            this.$message({
              message: '重置成功',
              type: 'success'
            });
            this.$router.push("/loginview")
          }else{
            this.$message({
              message: res.msg,
              type: 'error'
            });
          }
        })
      } else {
        this.$message.error("两次密码不一致!");
      }

    }
  }
}
</script>

